﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using iMusik.Resources;

namespace iMusik
{
    public partial class PhonePage : PhoneApplicationPage
    {
        private Point _MouseDownPoint;
        private Point _MouseUpPoint;

        // Constructor
        public PhonePage()
        {
            InitializeComponent();

            // Sample code to localize the ApplicationBar
            //BuildLocalizedApplicationBar();
            _MouseDownPoint = new Point();
            _MouseUpPoint = new Point();
        }

        protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
        {
            base.OnBackKeyPress(e);
            MessageBoxResult result = MessageBox.Show("Bạn có muốn thoát?", "THÔNG BÁO", MessageBoxButton.OKCancel);
            if (result == MessageBoxResult.OK)
            {
                while (this.NavigationService.BackStack.Any())
                {
                    this.NavigationService.RemoveBackEntry();
                }
                e.Cancel = false;
            }
            else
                e.Cancel = true;
        }

        private void Grid_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            string gridName = "";
            try
            {
                gridName = (sender as Grid).Name;
            }
            catch
            {
            }

            if (gridName == "_grdSong" || gridName == "_grdArtist" || gridName == "_grdAlbum")
            {
                string uri = "/PhonePage1.xaml?parameter=" + gridName;
                NavigationService.Navigate(new Uri(uri, UriKind.Relative));
            }
            else if (gridName == "_grdSearch" || gridName == "_grdFavorite" || gridName == "_grdSdCard")
            {
                string uri = "/PhonePage2.xaml?parameter=" + gridName;
                NavigationService.Navigate(new Uri(uri, UriKind.Relative));
            }
        }

        private void Status_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            _MouseDownPoint = e.GetPosition(_grdContent);
        }

        private void Status_MouseLeftButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            _MouseUpPoint = e.GetPosition(_grdContent);
            if (_MouseUpPoint.Y >= _MouseDownPoint.Y - 20 && _MouseUpPoint.Y <= _MouseDownPoint.Y + 20
                && _MouseDownPoint.X > _MouseUpPoint.X + 20)
            {
                string uri = "/Mp3ZingPage.xaml";
                NavigationService.Navigate(new Uri(uri, UriKind.Relative));
            }
        }
    }
}